package com.easylinkin.linkappapi.device.entity;


import com.easylinkin.linkappapi.common.utils.DateUtil;
import lombok.Data;

/**
 * <p>
 * 用于设备导出用
 * </p>
 *
 * @author TongJie
 * @since 2020-10-19
 */
@Data
public class DeviceVo extends Device {

    /**
     * 创建时间
     */
    private String createTimeStr;
    /**
     * 最近上报时间
     */
    private String lastPushTimeStr;

    /**
     * 模块名称
     */
    private String modelName;

    /**
     * 模块下的deviceTypeName，例如模块下喷淋设备类型对应的linkos设备类型为阀门控制器,三相智能断路器
     */
    private String modelDeviceTypeName;

    private Integer type;

    /**
     * 在线状态
     */
    private String onlineStateStr;

    public DeviceVo(Device device) {
        this.setCode(device.getCode());
        this.setName(device.getName());
        this.setDeviceTypeName(device.getDeviceTypeName());
        this.setDeviceUnitCode(device.getDeviceUnitCode());
        this.setAreaPath(device.getAreaPath());
        this.setLongitude(device.getLongitude());
        this.setLatitude(device.getLatitude());
        this.setIndoorLocation(device.getIndoorLocation());
        this.setSite(device.getSite());

        this.createTimeStr = device.getCreateTime() != null ? DateUtil.getYYYYMMDDHHMMSSDate(device.getCreateTime()) : null;
        this.lastPushTimeStr = device.getLastPushTime() != null ? DateUtil.getYYYYMMDDHHMMSSDate(device.getLastPushTime()) : null;
        this.onlineStateStr = "未知";
        if (device.getOnlineState() != null) {
            if (device.getOnlineState().equals(1)) {
                this.onlineStateStr = "在线";
            } else if (device.getOnlineState().equals(0)) {
                this.onlineStateStr = "离线";
            }
        }
        if (device.getLinkthingDelete() != null && device.getLinkthingDelete().equals(0)) {
            this.onlineStateStr = "已删";
        }
    }

    public DeviceVo() {
    }
}
